﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.HashUtilities
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using Unity.Collections.LowLevel.Unsafe;

#nullable disable
namespace UnityEngine
{
  /// <summary>
  ///   <para>Utilities to compute hashes.</para>
  /// </summary>
  public static class HashUtilities
  {
    public static unsafe void AppendHash(ref Hash128 inHash, ref Hash128 outHash)
    {
      fixed (Hash128* hash = &outHash)
        fixed (Hash128* data = &inHash)
          HashUnsafeUtilities.ComputeHash128((void*) data, (ulong) sizeof (Hash128), hash);
    }

    public static unsafe void QuantisedMatrixHash(ref Matrix4x4 value, ref Hash128 hash)
    {
      fixed (Hash128* hash1 = &hash)
      {
        int* data = stackalloc int[16];
        for (int index = 0; index < 16; ++index)
          data[index] = (int) ((double) value[index] * 1000.0 + 0.5);
        HashUnsafeUtilities.ComputeHash128((void*) data, 64UL, hash1);
      }
    }

    public static unsafe void QuantisedVectorHash(ref Vector3 value, ref Hash128 hash)
    {
      fixed (Hash128* hash1 = &hash)
      {
        int* data = stackalloc int[3];
        for (int index = 0; index < 3; ++index)
          data[index] = (int) ((double) value[index] * 1000.0 + 0.5);
        HashUnsafeUtilities.ComputeHash128((void*) data, 12UL, hash1);
      }
    }

    public static unsafe void ComputeHash128<T>(ref T value, ref Hash128 hash) where T : struct
    {
      HashUnsafeUtilities.ComputeHash128(UnsafeUtility.AddressOf<T>(ref value), (ulong) UnsafeUtility.SizeOf<T>(), (Hash128*) UnsafeUtility.AddressOf<Hash128>(ref hash));
    }

    public static unsafe void ComputeHash128(byte[] value, ref Hash128 hash)
    {
      fixed (byte* data = &value[0])
        HashUnsafeUtilities.ComputeHash128((void*) data, (ulong) value.Length, (Hash128*) UnsafeUtility.AddressOf<Hash128>(ref hash));
    }
  }
}
